package com.study.sxc.Dao;

import com.study.sxc.Entity.Usage;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface IUsageDao {
    @Select({
        "<script>",
        "select usage_id as usageId, machine_id as machineId, user_id as userId, staff_id as staffId, start_time as startTime, end_time as endTime, duration, cost, payment_status as paymentStatus",
        "from `usage`",
        "where usage_id in",
        "<foreach collection='list' item='id' open='(' separator=',' close=')'>",
        "#{id}",
        "</foreach>",
        "</script>"
    })
    List<Usage> getUsages(List<Integer> ids);

    @Insert("insert into `usage` (machine_id, user_id, staff_id, start_time, cost, payment_status) values (#{machineId}, #{userId}, #{staffId}, #{startTime}, #{cost}, #{paymentStatus})")
    @Options(useGeneratedKeys = true, keyProperty = "usageId")
    int addUsage(Usage usage);

    @Update("update `usage` set end_time = #{endTime}, duration = #{duration}, cost = #{cost}, payment_status=#{paymentStatus} where usage_id = #{usageId}")
    int updateUsage(Usage usage);

    @Delete("delete from `usage` where usage_id = #{id}")
    int deleteUsage(Integer id);

    @Select("select usage_id as usageId, machine_id as machineId, user_id as userId, staff_id as staffId, start_time as startTime, end_time as endTime, duration, cost, payment_status as paymentStatus from `usage` where usage_id = #{id}")
    Usage getUsageById(Integer id);

    @Select("select usage_id as usageId, machine_id as machineId, user_id as userId, staff_id as staffId, start_time as startTime, end_time as endTime, duration, cost, payment_status as paymentStatus from `usage`")
    java.util.List<Usage> getAllUsages();
} 